package com.ruoyi.web.controller.system;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.web.utils.FileNameUtil;
import com.ruoyi.web.utils.HttpResponse;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BabyState;
import com.ruoyi.system.service.IBabyStateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2021-11-26
 */
@RestController
@RequestMapping("/api/state")
public class BabyStateController extends BaseController
{
    @Autowired
    private IBabyStateService babyStateService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:state:list')")
    @GetMapping("/list")
    public TableDataInfo list(BabyState babyState)
    {
        startPage();
        List<BabyState> list = babyStateService.selectBabyStateList(babyState);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:state:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BabyState babyState)
    {
        List<BabyState> list = babyStateService.selectBabyStateList(babyState);
        ExcelUtil<BabyState> util = new ExcelUtil<BabyState>(BabyState.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:state:query')")
    @GetMapping(value = "/{stateId}")
    public AjaxResult getInfo(@PathVariable("stateId") String stateId)
    {
        return AjaxResult.success(babyStateService.selectBabyStateByStateId(stateId));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:state:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BabyState babyState)
    {
        return toAjax(babyStateService.insertBabyState(babyState));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:state:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BabyState babyState)
    {
        return toAjax(babyStateService.updateBabyState(babyState));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:state:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stateIds}")
    public AjaxResult remove(@PathVariable String[] stateIds)
    {
        return toAjax(babyStateService.deleteBabyStateByStateIds(stateIds));
    }

    @ApiOperation("获取列表")
    @GetMapping("/stateList")
    public TableDataInfo stateList(BabyState babyState)
    {
        startPage();
        List<BabyState> list = babyStateService.selectBabyStateList(babyState);
        return getDataTable(list);
    }

    @ApiOperation("新增记录")
    @RequestMapping(value = "/createState", method = RequestMethod.OPTIONS)
    public HttpResponse createStateRequest(@RequestBody BabyState babyState)
    {
        babyState.setStateId(FileNameUtil.getUUID());
        babyState.setStatus(0l);
        babyState.setIntoTime(FileNameUtil.formatDate(new Date()));
        int index = babyStateService.insertBabyState(babyState);
        if (index==1) {
            return HttpResponse.ok().setData(true);
        }else {
            return HttpResponse.error("新增失败");
        }
    }
}
